package zengyan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public abstract  class CommonAdapter<T> extends BaseAdapter {
	
	protected LayoutInflater mInflater;  
    protected Context mContext;  
    protected List<T> mDatas;  
    protected final int mItemLayoutId;
    
    
    public CommonAdapter(Context context,List<T> mDatas,int mitemLayoutId){
    	this.mContext=context;
    	this.mDatas=mDatas;
    	this.mInflater=LayoutInflater.from(context);
    	this.mItemLayoutId=mitemLayoutId;
    }
    

	@Override
	public int getCount() {
		return mDatas.size();
	}

	@Override
	public Object  getItem(int position) {
		// TODO Auto-generated method stub
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final ViewHolder viewholder=ViewHolder.get(mContext, convertView, parent, mItemLayoutId,  
                position);
		convert(viewholder, (T) getItem(position));

        return viewholder.getConvertView(); 
        
	}
	
	 public abstract void convert(ViewHolder helper, T item);  
	
	private ViewHolder getViewHolder(int position, View convertView,  
            ViewGroup parent)  
    {  
        return ViewHolder.get(mContext, convertView, parent, mItemLayoutId,  
                position);  
    }  

}
